//
//  CateSeeAllTableViewControllTableViewController.m
//  DanTang
//
//  Created by honeyrr on 2017/10/11.
//  Copyright © 2017年 honeyrr. All rights reserved.
//

#import "CateSeeAllTableViewControllTableViewController.h"
#import "CateSeeAllTableViewCell.h"
#import "CateTableViewController.h"

@interface CateSeeAllTableViewControllTableViewController ()
@property (nonatomic,strong) NSArray *collections;
@end

static NSString *const CateSeeAllTableViewCellID = @"CateSeeAllTableViewCellID";

@implementation CateSeeAllTableViewControllTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"全部专题";
    
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([CateSeeAllTableViewCell class]) bundle:nil] forCellReuseIdentifier:CateSeeAllTableViewCellID];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.rowHeight = 160;
    
    [[DTNetWork sharedNetWork]loadDataInfo:@"http://api.dantangapp.com/v1/collections?limit=20&offset=0" parameters:nil success:^(id  _Nullable responseObject) {
        
        self.collections = responseObject[@"data"][@"collections"];
        [self.tableView reloadData];
        
    } failure:^(NSError * _Nullable error) {
        
    }];
    
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.collections == nil ? 0:self.collections.count;
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CateSeeAllTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CateSeeAllTableViewCellID];
    cell.collection = self.collections[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CateTableViewController *detailVC = [[CateTableViewController alloc]init];
    detailVC.type = @"专题合集";
    detailVC._id = [self.collections[indexPath.row][@"id"] integerValue];
    detailVC.title = self.collections[indexPath.row][@"title"];
    [self.navigationController pushViewController:detailVC animated:YES];
}

@end
